<?php
Class admin_phuongthucController Extends baseController {

	public function index() { 
		$hangsanxuatModel = new phuongthucthanhtoan();
		//$current_page = (isset($_REQUEST['page'])) ? $_REQUEST['page'] : 1;
		//$pos = ($current_page -1 ) * __PAGE_SIZE;
		$lstTv = $hangsanxuatModel->getPhuongThucThanhToanByWhere('', '');
		//$count = count((array)$hangsanxuatModel->getAllHangSanXuatByWhere('', ''));
		//$pages = ceil($count/__PAGE_SIZE);

		$this->registry->template->lstHang = $lstTv;
		//$this->registry->template->pages = $pages;
		
		$this->registry->template->show('admin/phuongthuc_view');
	}
	
	public function edit(){
		if(isset($_REQUEST['phuongthuc_id'])){
			$phuongthuc_id = $_REQUEST['phuongthuc_id'];
			$hangModel = new phuongthucthanhtoan();
			$tivi = $hangModel->getPhuongThucThanhToanById($phuongthuc_id);
			if(count($tivi)>0){
				$this->registry->template->hang = $tivi;	
			}
		}
		$this->registry->template->show('admin/phuongthuc_edit');	
	}
	
	public function save(){
			
			$hang = new phuongthucthanhtoan();
			$hang->MoTa = trim($_POST['tmota']);
			$hang->PhiDichVu = trim($_POST['tphi']);
			$hang->TrangThai = $_POST['rtrangthai'];
			
			if(isset($_REQUEST['phuongthuc_id'])){
				$hang->id = trim($_GET['phuongthuc_id']);
				$rs = $hang->update($hang);
				
			}
			else{
				
				$rs = $hang->insert($hang);
			}
			
			if($rs){
				echo '<script>alert("thành công.");</script>';
				header('location:'.__URL_BASE.'index.php?rt=admin_phuongthuc');
				exit;
			}
			else{
				echo '<script>alert("Có lỗi xảy ra.");</script>';
			}
		}
		
		public function delete(){
			if(isset($_REQUEST['phuongthuc_id'])){
				$hangModel = new phuongthucthanhtoan();
				$hangModel->delete($_REQUEST['phuongthuc_id']);
				header('location:'.__URL_BASE.'index.php?rt=admin_phuongthuc');
				exit;
			}
		}

}
?>
